$(document)
		.ready(
				function() {

					// 存放选中的调度的领域接口的URL
					window.systemInterfaceUrl = null;
					// 存放选中的调度的运行状态
					window.runStatus = null;

					// 所属领域下拉框
					$('#comboxSearchfieldName')
							.combobox(
									{
										url : BASE_URL_FIELD_SEARCH
												+ '/findAllOfCurrentUserCanManage'
												+ '?v=' + Math.random(),
										valueField : 'id',
										textField : 'name',
										editable : false,
										method : 'get',
										loadFilter : function(data) {
											var allCheck = {
												'id' : '',
												'name' : '全部'
											};
											data.content.unshift(allCheck);
											return data.content;
										},
										onSelect : function(record) {
											comboxSearchSystemName
													.combobox(
															{
																disabled : false,
																method : 'get',
																queryParams : {
																	fieldId : record.id
																},
																url : BASE_URL_FIELD_SYSTEM_SEARCH
																		+ '/findByFieldOfCurrentUserCanManage'
																		+ '?v='
																		+ Math
																				.random(),
																valueField : 'id',
																textField : 'name',
																data : '',
																loadFilter : function(
																		data) {
																	var allCheck = {
																		'id' : '',
																		'name' : '全部'
																	};
																	data.content
																			.unshift(allCheck);
																	return data.content;
																},
																onLoadSuccess : function() {
																	comboxSearchSystemName
																			.combobox(
																					'setValue',
																					'');
																}
															}).load();
										},
										onLoadSuccess : function() {
											$('#comboxSearchfieldName')
													.combobox('setValue', '');
										}
									});

					// 所属系统下拉框
					var comboxSearchSystemName = $('#comboxSearchSystemName')
							.combobox({
								disabled : true,
								valueField : 'id',
								textField : 'name',
								editable : false,
								data : [ {
									id : '',
									name : '全部',
									'selected' : 'true'
								} ]
							});

					$('#comboxFieldName')
							.combobox(
									{
										url : BASE_URL_FIELD_SEARCH
												+ '/findAllOfCurrentUserCanManage'
												+ '?v=' + Math.random(),
										valueField : 'id',
										textField : 'name',
										editable : false,
										method : 'get',
										loadFilter : function(data) {
											var allCheck = {
												'id' : '',
												'name' : '请选择'
											};
											if (data.content) {
												data.content.unshift(allCheck);
											} else {
												return data;
											}
											return data.content;
										},
										onSelect : function(record) {
											comboxSystemName
													.combobox(
															{
																disabled : false,
																method : 'get',
																queryParams : {
																	fieldId : record.id
																},
																url : BASE_URL_FIELD_SYSTEM_SEARCH
																		+ '/findByFieldOfCurrentUserCanManage'
																		+ '?v='
																		+ Math
																				.random(),
																valueField : 'id',
																textField : 'name',
																data : '',
																loadFilter : function(
																		data) {

																	var allCheck = {
																		'id' : '',
																		'name' : '请选择'
																	};
																	data.content
																			.unshift(allCheck);
																	return data.content;
																},
																onSelect : function(
																		record) {
																	comboxInterface
																			.combobox({
																				disabled : false,
																				method : 'get',
																				queryParams : {
																					fieldSystemId : record.id
																				},
																				url : BASE_URL_SYSTEM_INTERFACE_SEARCH
																						+ '/findByOwnerFieldSystem_Id'
																						+ '?v='
																						+ Math
																								.random(),
																				valueField : 'id',
																				textField : 'jobName',
																				data : '',
																				loadFilter : function(
																						data) {
																					if (data[0].id == "") {
																						return data;
																					}
																					var allCheck = {
																						'id' : '',
																						'jobName' : '请选择'
																					};
																					data
																							.unshift(allCheck);
																					return data;

																				},
																				onLoadSuccess : function() {
																					$(
																							'#comboxInterface')
																							.combobox(
																									'setValue',
																									'');
																				}
																			});
																},
																onLoadSuccess : function() {
																	$(
																			'#comboxInterface')
																			.combobox(
																					'setValue',
																					'');

																}
															}).load();
											comboxInterface.combobox({
												disabled : true,
												valueField : 'id',
												textField : 'jobName',
												editable : false,
												url : '',
												data : [],
												loadFilter : function(data) {
													var allCheck = {
														id : '',
														jobName : '请选择',
														'selected' : 'true'
													};
													data.unshift(allCheck);
													return data;
												}
											});
										}

									});

					var comboxSystemName = $('#comboxSystemName').combobox({
						disabled : true,
						valueField : 'id',
						textField : 'name',
						editable : false,
						url : '',
						data : [],
						loadFilter : function(data) {
							var allCheck = {
								id : '',
								name : '请选择',
								'selected' : 'true'
							};
							data.unshift(allCheck);
							return data;
						}

					});
					// 请求结果下拉框
					$('#comboxAlarmType').combobox(
							{
								url : BASE_URL_DATA_DICTIONARY_VALUE_SEARCH
										+ '/findByTypeCode?typeCode='
										+ DDTC_ALARM_TYPE + '&v='
										+ Math.random(),
								valueField : 'valueCode',
								textField : 'valueName',
								editable : false,
								method : 'get',
								loadFilter : function(data) {
									var allCheck = {
										'valueCode' : '',
										'valueName' : '全部'
									};
									data.unshift(allCheck);
									return data;
								}
							});
			$("#datagrid").datagrid({
			url:BASE_URL_API + '/serviceAlarmStatistics/findServiceAlarmStatisticsInfo?v='+ Math.random(),
			method:'get',
			autoRowHeight:true,
			singleSelect:true,
			striped:true,
			nowrap:false,
			pageSize:20,
			pageList:[10,20,50,100],
			columns:[[												
						{field:'fieldName',title:'所属领域',align:'center',width:80,resizable:true},	
						{field:'systemName',title:'所属系统',width:80,sortable:true},
						{field:'ifName',title:'接口名称',width:160},
						{field:'ifStatus',title:'服务状态',width:60,
							formatter : function(value,rowData, rowIndex) {
								return value == '0' ? '停用': (value == '1' ? '启用': '');
							}},
						{field:'alarmType',title:'报警类型',width:50,
							formatter : function(value,
									rowData, rowIndex) {
								return value == '1' ? '请求超时'
										: (value == '2' ? '请求超限'
												: 'Http400错误');
							}},
						{field:'times',title:'次数',width:130}
			      ]],
			pagination:true,
			onSelect:function(rowIndex,rowData){
				$("#toolbar_edit").linkbutton('enable');
				$("#toolbar_delete").linkbutton('enable');
				$(this).datagrid('unselectRow', rowIndex);
			},
			loadFilter:function(data){
		// alert("inData:"+JSON.stringify(data));
		// console.log(data);
				
				return {
					total: data.totalElements,
					rows: data.content
				};
			},
			onBeforeLoad:function(param){
				param.page -= 1;
				param.size = param.rows;
				delete param.rows;
				var ifName = $('#txtSearchIfName').val();
				if (ifName != "") {
					param.ifName = ifName;
				}
				var systemId = $('#comboxSearchSystemName').combobox('getValue');
				if (systemId != "") {
					param.systemId = systemId;
				}
				var fieldId = $('#comboxSearchfieldName').combobox('getValue');
				if (fieldId != "") {
					param.fieldId = fieldId;
				}
				var alarmType = $('#comboxAlarmType').combobox('getValue');
				if (alarmType != "") {
					param.alarmType = alarmType;
				}
				var startDate = $("#txtStartDateTime").datebox('getValue');
				if (startDate != "") {
					param.startDate = startDate;
				}
				var endDate = $("#txtEndDateTime").datebox('getValue');
				if (endDate != "") {
					param.endDate = endDate;
				}
			}
		});		   
		    
		$("#datagrid").datagrid('getPager').pagination({   
		    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录'
		}); 
});	
function search(){
	$("#datagrid").datagrid('reload');
			
}
					
function　exportData(){
	var ifName = $('#txtSearchIfName').val();
	var systemId = $('#comboxSearchSystemName').combobox('getValue');
	var fieldId = $('#comboxSearchfieldName').combobox('getValue');
	var alarmType = $('#comboxAlarmType').combobox('getValue');
	var startDate = $("#txtStartDateTime").datebox('getValue');
	var endDate = $("#txtEndDateTime").datebox('getValue');

	var param = '{"ifName":"' + ifName + '","systemId":"' + systemId + '" ,"fieldId":"' + fieldId + '" ,'
	+ '"alarmType":"' + alarmType + '","startDate":"' + startDate
	+ '" ,' + '"endDate":"' + endDate + '"}';
	
	location.href= BASE_URL_API + '/serviceAlarmStatistics/export?param='+param+'&v='+ Math.random();
}
		